--[[
	Do not re-distribute or modify
	without permission of its author Shoop (Aka. Jakeb34).
-- ________________________________________________________________________________________________________________________________________
--]]




local mindcontrol = {} -- Parent window and main script


function mindcontrol.speedcheck()
	if(speed < 1)then
			
	else
		speed = speed - 1
	end
end



function mindcontrol.carbrake()
	local playerPed = PLAYER.PLAYER_PED_ID()
	local PedTab,PedCount = PED.GET_PED_NEARBY_PEDS(playerPed, 1, 1)
	local VehTab,VehCount = PED.GET_PED_NEARBY_VEHICLES(playerPed, 1)
	
	for k,v in ipairs(VehTab)do 
		local PlayerVeh = PED.IS_PED_IN_VEHICLE(playerPed, v, false)
		if(PlayerVeh == true)then
		
		else
	
			speed = ENTITY.GET_ENTITY_SPEED(v)
			for i = 1,60 do
				VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed)
				mindcontrol.speedcheck()
				ENTITY.SET_ENTITY_VELOCITY(v, 0, 0, 0)
			end
		end
	end
		
end

function mindcontrol.anger()
	local playerPed = PLAYER.PLAYER_PED_ID()
	local PedTab,PedCount = PED.GET_PED_NEARBY_PEDS(playerPed, 1, 1)
	local VehTab,VehCount = PED.GET_PED_NEARBY_VEHICLES(playerPed, 1)
	
	for k,v in ipairs(PedTab)do 
		PED.SET_PED_AS_ENEMY(v, true)
	end
		
end

function mindcontrol.calm()
	local playerPed = PLAYER.PLAYER_PED_ID()
	local PedTab,PedCount = PED.GET_PED_NEARBY_PEDS(playerPed, 1, 1)
	local VehTab,VehCount = PED.GET_PED_NEARBY_VEHICLES(playerPed, 1)
	
	for k,v in ipairs(PedTab)do 
		PED.SET_PED_AS_ENEMY(v, false)
	end
		
end




function mindcontrol.carexplode()
	local playerPed = PLAYER.PLAYER_PED_ID()
	local PedTab,PedCount = PED.GET_PED_NEARBY_PEDS(playerPed, 1, 1)
	local VehTab,VehCount = PED.GET_PED_NEARBY_VEHICLES(playerPed, 1)
	
	for k,v in ipairs(VehTab)do 
		local PlayerVeh = PED.IS_PED_IN_VEHICLE(playerPed, v, false)
		if(PlayerVeh == true)then
		
		else
			VEHICLE.EXPLODE_VEHICLE(v, true, true)
		end
	end
	
end

function mindcontrol.alarm()
	local playerPed = PLAYER.PLAYER_PED_ID()
	local PedTab,PedCount = PED.GET_PED_NEARBY_PEDS(playerPed, 1, 1)
	local VehTab,VehCount = PED.GET_PED_NEARBY_VEHICLES(playerPed, 1)
	
	for k,v in ipairs(VehTab)do 
		VEHICLE.SET_VEHICLE_ALARM(v, true)
		VEHICLE.START_VEHICLE_ALARM(v)
	end
	
end

function mindcontrol.steerfault()
	local playerPed = PLAYER.PLAYER_PED_ID()
	local PedTab,PedCount = PED.GET_PED_NEARBY_PEDS(playerPed, 1, 1)
	local VehTab,VehCount = PED.GET_PED_NEARBY_VEHICLES(playerPed, 1)
	
	for k,v in ipairs(VehTab)do 
		local PlayerVeh = PED.IS_PED_IN_VEHICLE(playerPed, v, false)
		if(PlayerVeh == true)then
		
		else
			VEHICLE.SET_VEHICLE_OUT_OF_CONTROL(v, true, false)
			-- VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, 40)
		end
	end

end

function mindcontrol.forceforward()
	local playerPed = PLAYER.PLAYER_PED_ID()
	local PedTab,PedCount = PED.GET_PED_NEARBY_PEDS(playerPed, 1, 1)
	local VehTab,VehCount = PED.GET_PED_NEARBY_VEHICLES(playerPed, 1)
	
	for k,v in ipairs(VehTab)do
		local PlayerVeh = PED.IS_PED_IN_VEHICLE(playerPed, v, false)
		if(PlayerVeh == true)then
		
		else
			speed = ENTITY.GET_ENTITY_SPEED(v)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 1)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 2)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 3)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 4)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 5)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 6)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 7)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 8)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 9)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 10)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 11)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 12)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 13)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 14)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 15)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 16)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 17)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 18)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 19)
			VEHICLE.SET_VEHICLE_FORWARD_SPEED(v, speed + 20)
		end
	end

end

function mindcontrol.burnout()
	local playerPed = PLAYER.PLAYER_PED_ID()
	local PedTab,PedCount = PED.GET_PED_NEARBY_PEDS(playerPed, 1, 1)
	local VehTab,VehCount = PED.GET_PED_NEARBY_VEHICLES(playerPed, 1)
	
	
	for k,v in ipairs(VehTab)do 
		local PlayerVeh = PED.IS_PED_IN_VEHICLE(playerPed, v, false)
		if(PlayerVeh == true)then
		
		else
			VEHICLE.SET_VEHICLE_BURNOUT(v, true)
		end
	end
	
end

function mindcontrol.jump()
	local playerPed = PLAYER.PLAYER_PED_ID()
	local PedTab,PedCount = PED.GET_PED_NEARBY_PEDS(playerPed, 1, 1)
	local VehTab,VehCount = PED.GET_PED_NEARBY_VEHICLES(playerPed, 1)
	
	for k,v in ipairs(PedTab)do 
		vehCheck = PED.IS_PED_IN_ANY_VEHICLE(v, false)
		if(vehCheck == false)then
			AI.TASK_JUMP(v, true)
		else
		end
	end
	
end

function mindcontrol.scare()
	local playerPed = PLAYER.PLAYER_PED_ID()
	local PedTab,PedCount = PED.GET_PED_NEARBY_PEDS(playerPed, 1, 1)
	local VehTab,VehCount = PED.GET_PED_NEARBY_VEHICLES(playerPed, 1)
	
	for k,v in ipairs(PedTab)do 
		vehCheck = PED.IS_PED_IN_ANY_VEHICLE(v, false)
		if(vehCheck == false)then
			AI.TASK_COWER(v, 20)
		else
		end
	end
	
end

function mindcontrol.destroyengine()
	local playerPed = PLAYER.PLAYER_PED_ID()
	local PedTab,PedCount = PED.GET_PED_NEARBY_PEDS(playerPed, 1, 1)
	local VehTab,VehCount = PED.GET_PED_NEARBY_VEHICLES(playerPed, 1)
	
	for k,v in ipairs(VehTab)do 
		local PlayerVeh = PED.IS_PED_IN_VEHICLE(playerPed, v, false)
		if(PlayerVeh == true)then
		
		else
			VEHICLE.SET_VEHICLE_ENGINE_HEALTH(v, 0)
		end
	end
	
end

function mindcontrol.ragdoll()
	local playerPed = PLAYER.PLAYER_PED_ID()
	local PedTab,PedCount = PED.GET_PED_NEARBY_PEDS(playerPed, 1, 1)
	local VehTab,VehCount = PED.GET_PED_NEARBY_VEHICLES(playerPed, 1)
	
	for k,v in ipairs(PedTab)do 
		PED.SET_PED_TO_RAGDOLL(v, 6, 20, 20, TRUE, TRUE, TRUE);
	end
		
end

function mindcontrol.disguise()
	local PedTab = {}
	local PedCount = {}
	local player = PLAYER.PLAYER_ID()
	local playerPed = PLAYER.PLAYER_PED_ID()
	local PedTab,PedCount = PED.GET_PED_NEARBY_PEDS(playerPed, 1, 1)
	local VehTab,VehCount = PED.GET_PED_NEARBY_VEHICLES(playerPed, 1)
	defmdl = ENTITY.GET_ENTITY_MODEL(playerPed)
	
	for k,v in ipairs(PedTab)do
		local model = ENTITY.GET_ENTITY_MODEL(PedTab[1])
		PLAYER.SET_PLAYER_MODEL(player, model)
		PLAYER.CLEAR_PLAYER_WANTED_LEVEL(player) -- When you disguise you lose wanted level!
	end
end

function mindcontrol.removedis()
	local player = PLAYER.PLAYER_ID()
	PLAYER.SET_PLAYER_MODEL(player, initmodel)
end

function mindcontrol.slay()
	local playerPed = PLAYER.PLAYER_PED_ID()
	local PedTab,PedCount = PED.GET_PED_NEARBY_PEDS(playerPed, 1, 1)
	local VehTab,VehCount = PED.GET_PED_NEARBY_VEHICLES(playerPed, 1)
	
	for k,v in ipairs(PedTab)do 
		if(v == playerPed)then
		
		else
			ENTITY.SET_ENTITY_HEALTH(v, 0)
		end
	end
end

function mindcontrol.heal()
	local playerPed = PLAYER.PLAYER_PED_ID()
	local PedTab,PedCount = PED.GET_PED_NEARBY_PEDS(playerPed, 1, 1)
	local VehTab,VehCount = PED.GET_PED_NEARBY_VEHICLES(playerPed, 1)
	
	for k,v in ipairs(PedTab)do 
		ENTITY.SET_ENTITY_HEALTH(v, 100)
	end
end





function mindcontrol.init()

	mindcontrol.GUI = Libs["GUI"] -- Main, Parent window
	
	local playerPed = PLAYER.PLAYER_PED_ID()
	initmodel = ENTITY.GET_ENTITY_MODEL(playerPed)
	
	mindcontrol.GUI.addButton("Force Car Brakes",mindcontrol.carbrake,nil,0,0.2,0.05,0.07)
	mindcontrol.GUI.addButton("Destroy Engine",mindcontrol.destroyengine,nil,0,0.2,0.05,0.07)
	mindcontrol.GUI.addButton("Force accelerate",mindcontrol.forceforward,nil,0,0.2,0.05,0.07)
	mindcontrol.GUI.addButton("Explode Cars",mindcontrol.carexplode,nil,0,0.2,0.05,0.07)
	mindcontrol.GUI.addButton("Alarm Malfunction",mindcontrol.alarm,nil,0,0.2,0.05,0.07)
	mindcontrol.GUI.addButton("Knockout Drivers",mindcontrol.steerfault,nil,0,0.2,0.05,0.07)
	mindcontrol.GUI.addButton("Break Car Brakes",mindcontrol.burnout,nil,0,0.2,0.05,0.07)
	mindcontrol.GUI.addButton("Make Peds Jump",mindcontrol.jump,nil,0,0.2,0.05,0.07)
	mindcontrol.GUI.addButton("Scare Peds",mindcontrol.scare,nil,0,0.2,0.05,0.07) 
	--mindcontrol.GUI.addButton("Anger Peds",mindcontrol.anger,nil,0,0.2,0.05,0.07) 
	--mindcontrol.GUI.addButton("Calm Peds",mindcontrol.calm,nil,0,0.2,0.05,0.07)
	mindcontrol.GUI.addButton("Ragdoll Peds",mindcontrol.ragdoll,nil,0,0.2,0.05,0.07)
	mindcontrol.GUI.addButton("Disguise",mindcontrol.disguise,nil,0,0.2,0.05,0.07)
	mindcontrol.GUI.addButton("Remove Disguise",mindcontrol.removedis,nil,0,0.2,0.05,0.07)
	mindcontrol.GUI.addButton("Slay Peds",mindcontrol.slay,nil,0,0.2,0.05,0.07)
	
	-- Parent Window -- [Hide all at startup]
	mindcontrol.GUI.hidden = true

end

-- Force Car Brakes
-- Destroy Engine
-- Force accellerate
-- Explode cars
-- Alarm Malfunction
-- Knockout Drivers
-- Break Car brakes
-- Make peds jump
-- Scare Peds
-- Ragdoll peds
-- Disguise
-- Remove Disguise
-- Slay Peds

function mindcontrol.tick()
	
mindcontrol.GUI.tick()


	local player = PLAYER.PLAYER_ID()
	local playerPed = PLAYER.PLAYER_PED_ID()
	local deathcheck = PLAYER.IS_PLAYER_DEAD(player)

	Keys.menuopen = 191
	Keys.menuclose = 8
	
	if(deathcheck == true)then
		PLAYER.SET_PLAYER_MODEL(player, initmodel) -- Should fix a bug with player death causing freeze. -- Yep Fixes it
	else
	end

	if(get_key_pressed(Keys.menuopen))then
		mindcontrol.GUI.hidden = false

	elseif(get_key_pressed(Keys.menuclose))then
		mindcontrol.GUI.hidden = true
	end
end

return mindcontrol